<template>
    <!-- 弹出框一 -->
    <vol-box :lazy="true" v-model="delModel" title="暂停作业的批次异常作废" :width="700" :padding="5" :onModelClose="onModelClose">
        <div style="padding: 15px 20px 15px 5px">
            <vol-form ref="form"
            :labelWidth="80"
            :load-key="false"
            :formFields="fields"
            :formRules="formOptions">
        </vol-form>
        </div>
        <template #footer>
            <div>
                <el-button type="primary" size="small" @click="Submit">确认</el-button>
                <el-button type="default" size="small" @click="delModel = false">关闭</el-button>
            </div>
        </template>
    </vol-box>
</template>
<script>
import VolBox from '@/components/basic/VolBox.vue';
//这里使用的vue2语法，也可以写成vue3语法
export default {
    components: { 'vol-box': VolBox },
    methods: {}, 
    data() {
        return {
            delModel: false,
            delModelRows: {}, //弹出框1传入的选中行
            fields: {"BatchCode":"","ProductCode":"","Quantity":"","Memo":"","ProductName":"","P_Quantity":"","F_Quantity":""},
            formOptions:[
                         [{"title":"批次编码","required":true,"field":"BatchCode","colSize":8,"disabled":true},
                          {"title":"作废数量/pcs","required":true,"field":"Quantity","type":"number","colSize":4,"min":1,"max":10000}],

                          [
                          {"title":"物料编码","field":"ProductCode",type:"label","disabled":true},
                          {"title":"物料名称","field":"ProductName",type:"label","disabled":true}
                          ],
                          [
                          {"title":"计划数量/pcs","field":"P_Quantity",type:"label","disabled":true},
                          {"title":"完工数量/pcs","field":"F_Quantity",type:"label","disabled":true},
                          ],
                        [{"title":"备注","field":"Memo", type:"textarea",autosize:"{ minRows: 2, maxRows: 2}","colSize":12}]
                        ],
             setData:[]

        };
    },
    methods: {
        openModel(rows) { //弹出框1
            this.delModelRows = rows;
            this.fields.BatchCode= rows.BatchCode;
            this.fields.ProductCode= rows.ProductCode;  
            this.fields.F_Quantity=rows.FinishQuantity;
            this.fields.P_Quantity=rows.Quantity;
            this.fields.ProductName=rows.ProductName;
            let maxNum=rows.Quantity-rows.FinishQuantity;
            this.fields.Quantity= maxNum;
            this.formOptions.forEach((op) => {
                op.forEach((item) => {
                    if(item.field == 'Quantity'){
                        item.min=1;
                        item.max=maxNum; }
                    })
                });
            this.delModel = true;
        },
        Submit() {
            //let setData=[];
            //this.fields;
            const itemdate=Object.assign({},{'batchID':this.delModelRows.BatchID,'BatchCode':this.delModelRows.BatchCode,
            'status':-1},{'Quantity':this.fields.Quantity,'Memo':this.fields.Memo})           
       
            this.http.post("/api/productionbatchesview/SetWorkBathStatusRemove", itemdate, '').then(date => {
                if (date.status) {
                            this.$message.info('批次作废成功'+date.message);
                        }
                        else{ 
                            this.$message.error('批次作废失败：'+date.message);
                        }
            this.$emit('parentCall', $parent => {
                //$parent就是生成页面的对象，比如可以调用页面刷新，可获取的属性与方法见【生成页面文档】,$parent.xxx直接调用
                //调用刷新
                $parent.search();
                
            })
            this.delModel = false;
            })
        },
        onModelClose() {
            this.$message.success('弹出框右上角点击x关闭事件')
        }
    }
};
</script>
  
